package com.fz.service.system.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fz.common.ResponseEntity;
import com.fz.dto.system.dept.DeptAdd;
import com.fz.dto.system.dept.DeptQuery;
import com.fz.dto.system.dept.DeptUpd;
import com.fz.entity.system.Dept;
import com.fz.mapper.system.DeptMapper;
import com.fz.service.system.DeptService;
import com.fz.vo.system.dept.DeptVo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

@Service
@SuppressWarnings("unchecked")
public class DeptServiceImpl implements DeptService {

    @Resource
    private DeptMapper deptMapper;

    /**
     * @方法描述:  分页查找部门
     * @参数:
     * @返回值:
     * @创建人: shy
     * @创建时间:: 2021/3/17
     */
    @Override
    public ResponseEntity<IPage<DeptVo>> findDeptList(DeptQuery deptQuery, int pageNum, int pageSize) throws Exception {
        Page<Dept> page = new Page<>(pageNum,pageSize);
        IPage<DeptVo> DeptQueryDataList = deptMapper.findDeptList(page,deptQuery);
        return ResponseEntity.buildSuccess(DeptQueryDataList);
    }

    /**
     * @方法描述:  新增部门
     * @参数:
     * @返回值:
     * @创建人: shy
     * @创建时间:: 2021/3/17
     */
    @Override
    public ResponseEntity addDept(DeptAdd deptAdd) {
        Dept dept = new Dept();
        dept.setName(deptAdd.getName());
        dept.setPid(deptAdd.getPid());
        dept.setStatus(deptAdd.getStatus());
        deptMapper.insert(dept);
        return ResponseEntity.buildSuccess();
    }

    /**
     * @方法描述:  更改部门
     * @参数:
     * @返回值:
     * @创建人: shy
     * @创建时间:: 2021/3/17
     */
    @Override
    public ResponseEntity updateDept(DeptUpd deptUpd) {
        Dept dept = new Dept();
        dept.setId(deptUpd.getId());
        dept.setStatus(deptUpd.getStatus());
        dept.setName(deptUpd.getName());
        dept.setPid(deptUpd.getPid());
        deptMapper.updateById(dept);
        return ResponseEntity.buildSuccess();
    }

    /**
     * @方法描述:  查询下拉框内部门的信息
     * @参数:
     * @返回值:
     * @创建人: shy
     * @创建时间:: 2021/3/19
     */
    @Override
    public ResponseEntity<List<Dept>> findDeptInSelect() {
        LambdaQueryWrapper<Dept> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        //  1    是禁用的状态标识符，查询被禁用的公司
        lambdaQueryWrapper.eq(Dept::getStatus, 1);
        List<Dept> deptVos = deptMapper.selectList(lambdaQueryWrapper);
        return ResponseEntity.buildSuccess(deptVos);
    }
}
